package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.INSURANCE;
import com.ruoyi.system.service.IINSURANCEService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 保险Controller
 * 
 * @author ruoyi
 * @date 2021-11-09
 */
@Controller
@RequestMapping("/system/INSURANCE")
public class INSURANCEController extends BaseController
{
    private String prefix = "system/INSURANCE";

    @Autowired
    private IINSURANCEService iNSURANCEService;

    @RequiresPermissions("system:INSURANCE:view")
    @GetMapping()
    public String INSURANCE()
    {
        return prefix + "/INSURANCE";
    }

    /**
     * 查询保险列表
     */
    @RequiresPermissions("system:INSURANCE:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(INSURANCE iNSURANCE)
    {
        startPage();
        List<INSURANCE> list = iNSURANCEService.selectINSURANCEList(iNSURANCE);
        return getDataTable(list);
    }

    /**
     * 导出保险列表
     */
    @RequiresPermissions("system:INSURANCE:export")
    @Log(title = "保险", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(INSURANCE iNSURANCE)
    {
        List<INSURANCE> list = iNSURANCEService.selectINSURANCEList(iNSURANCE);
        ExcelUtil<INSURANCE> util = new ExcelUtil<INSURANCE>(INSURANCE.class);
        return util.exportExcel(list, "保险数据");
    }

    /**
     * 新增保险
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存保险
     */
    @RequiresPermissions("system:INSURANCE:add")
    @Log(title = "保险", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(INSURANCE iNSURANCE)
    {
        return toAjax(iNSURANCEService.insertINSURANCE(iNSURANCE));
    }

    /**
     * 修改保险
     */
    @GetMapping("/edit/{insuranceId}")
    public String edit(@PathVariable("insuranceId") String insuranceId, ModelMap mmap)
    {
        INSURANCE iNSURANCE = iNSURANCEService.selectINSURANCEByInsuranceId(insuranceId);
        mmap.put("iNSURANCE", iNSURANCE);
        return prefix + "/edit";
    }

    /**
     * 修改保存保险
     */
    @RequiresPermissions("system:INSURANCE:edit")
    @Log(title = "保险", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(INSURANCE iNSURANCE)
    {
        return toAjax(iNSURANCEService.updateINSURANCE(iNSURANCE));
    }

    /**
     * 删除保险
     */
    @RequiresPermissions("system:INSURANCE:remove")
    @Log(title = "保险", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(iNSURANCEService.deleteINSURANCEByInsuranceIds(ids));
    }
}
